package com.clstu.regexp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 演示反向引用案例
 */
public class RegExp08 {
    public static void main(String[] args) {
        String content = "112211-9998887772213333655634434435566";
//        String regStr = "(\\d)\\1";//连续两个相同的数字 分组后面的(\\组号)就表示反向引用哪一组
//        String regStr = "(\\d)\\1{4}";//连续5个相同的数字
//        String regStr = "(\\d)(\\d)\\2\\1";//匹配abba类型的数字
        /**
         * 匹配要求:五位数-aaabbbccc
         */
        String regStr = "\\d{5}-(\\d)\\1{2}(\\d)\\2{2}(\\d)\\3{2}";
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()){
            System.out.println(matcher.group(0));
            System.out.println("1组:"+matcher.group(1));
        }

    }
}
